<?php
class FileLoggerAdapter
{
	// 日期格式
    private static $_format = '[ c ]';
    
	public function save($message, $level, $extra = "")
	{
		$destination = $this->_getDestination();
		$now = date(self::$_format);
		$log = "{$now} {$level}: {$message}\r\n";
    	error_log($log, 3, $destination, $extra);
	}
	
	
	private function _getDestination()
	{
		$file_path = YucyConfig::get('log_path') . DS . date('Y_m') . DS . date('d') . DS;
		if (!file_exists($file_path)) $this->_mkDir($file_path);
		
		return $file_path . date('y_m_d_H').".log";
	}
	
	
	private function _mkDir($dir, $mode = 0755)
	{
	  if (is_dir($dir) || @mkdir($dir,$mode)) return true;
	  if (!$this->_mkDir(dirname($dir),$mode)) return false;
	  return @mkdir($dir,$mode);
	}
}